using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Service : EveProperty
    {
        private string serviceName;
        private string description;
        private List<Operation> operations;

        public string Name
        {
            get { return serviceName; }
        }
        public string Description
        {
            get { return description; }
        }
        public List<Operation> Operations
        {
            get
            {
                if (operations == null)
                {
                    operations = new List<Operation>();
                    string query = "SELECT staOperations.* FROM staOperations, staOperationServices WHERE staOperations.operationID=staOperationServices.operationID AND staOperationServices.serviceID=" + Id;
                    foreach (DbDataRow row in db.ExecuteQuery(query))
                        operations.Add(new Operation(row));
                }
                return operations;
            }
        }

        internal Service(DbDataRow dr)
            : base(dr.Database, EvePropertyType.Service, dr["serviceID"])
        {
            Fill(dr);
        }
        internal Service(Database db, int id)
            : base(db, EvePropertyType.Service, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM staServices WHERE serviceID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            serviceName = dr["serviceName"];
            description = dr["description"];
        }
    }
}
